package com.baizhi.log.listener;

import com.baizhi.log.entity.Log;
import com.baizhi.log.service.ILogService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class LogQueueConsumer {
    @Autowired
    private ILogService ls;
    @RabbitListener(queues = "QA")
    public void receiveD(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        ObjectMapper mapper=new ObjectMapper();
        Log log = mapper.readValue(msg, Log.class);
        ls.save(log);
    }
}
